<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>云笔记登录</title>
    <style type="text/css">
        body{background-color:#f5f5f5}
    </style>
    <link rel="stylesheet" href="css/start.css">

    <script type="text/javascript" language="JavaScript"></script>

</head>


<body>
<div id="containter">
    <h2>云笔记登录</h2>
    <!--<form action="Main.html" method="post" name="load"></form>-->
    <div class="username">
        <input type="text" id="username" class="input_control" placeholder="请输入您的用户名" onblur="login1()"><span id="s1"></span>
    </div>
    <div class="password">
        <input type="password" id="password" class="input_control" placeholder="请输入您的密码" onblur="login2()"><span id="s2"></span>
    </div>
    <div class="autologin">
        <label class="login_label" style="display: block;"><input type="checkbox" checked="checked">自动登录</label>
        <a class="login_nopasswd" href=""  style="display:block;">忘记密码？</a>
    </div>
    <div class="buttons">
        <input id="login_button" type="button" value="登录" >
        <input class="register_button" type="button" value="注册" >
        <input id="test" type="button" value="测试">
    </div>
</div>
<label class="team" style="display:block;">@ wedo团队</label>

<script>
    function login1()
    {
        var myname=document.getElementById("username");
//            var myReg=/^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;
//            if(!myReg.test(myemail.value)){
//                document.getElementById("s1").innerHTML="邮箱格式错误！";
//                myemail.value="";
//                myemail.focus();
//            }
        if(myname.value==""){
            document.getElementById("s1").inneHTML="用户名不能为空！";
        }
        else
        {
            document.getElementById("s1").innerHTML="";
        }
    }
    function login2()
    {
        var p1=document.getElementById("password");
        if(p1.value=="")
        {
            document.getElementById("s2").inneHTML="密码不能为空！";
            p1.focus();
        }
        else
        {
            document.getElementById("s2").innerHTML="";
        }
    }

    var login_button=document.getElementById("login_button");
    var register_button=document.getElementsByClassName("register_button")[0];
    var test=document.getElementById("test");

    test.onclick=function(){
        var request=new XMLHttpRequest();
        request.open("POST","localhost:8888/i/noteuser/noteUser/login",true);//url  没写
        var data="userName="+document.getElementById("username").value
                +"&password="+document.getElementById("password").value;
        request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        request.onreadystatechange=function(){
            if(request.readyState==4)
            {
                if(request.status==200)
                {
                    var results=JSON.parse(request.responseText);
                    if(results.result==0){
                        alert("登录失败");
                    }
                    else alert("登录成功！");
                }
                else
                {
                    alert("发生错误："+request.status);
                }
            }
        }
        request.send(data);
    }
    register_button.onclick=function(){
        window.location.href="register_main.html";
    }
</script>
</body>
</html>